package fausto 
{
	import com.greensock.TweenMax;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	/**
	 * ...
	 * @author Ben.
	 */
	public class MenuItem extends Sprite
	{
		public var _txt:TextField
		public var _id:int
		
		private var _selected:Boolean = false;
		private var _name:String;
		
		public function MenuItem(s:String, i:int, sl:Boolean = false):void 
		{
			_id = i;
			_txt.autoSize = TextFieldAutoSize.LEFT;
			_txt.htmlText = "./ " + s;
			
			_name = s;
			
			buttonMode = true;
			mouseChildren = false;
			
			addEventListener(MouseEvent.ROLL_OVER, onOver);
			addEventListener(MouseEvent.ROLL_OUT, onOut);
			addEventListener(MouseEvent.CLICK, onClick);
			
			if (sl)
			{
				_selected = true;
				onSelect();
			}
			
		}
		
		private function onClick(e:MouseEvent):void 
		{
			if (!_selected)
			{
				_selected = true;
				dispatchEvent(new Event("MENU_CLICK", true));
			}
			
		}
		
		private function onOut(e:MouseEvent):void 
		{
			if (!_selected)
			{
				onUnselect();
			}
		}
		
		public function onUnselect():void 
		{
			TweenMax.to(this, 0, { tint:0x868686 } );
		}
		
		private function onOver(e:MouseEvent):void 
		{
			
			if (!_selected)
			{
				onSelect();
			}
		}
		
		public function onSelect():void 
		{
			TweenMax.to(this, 0, { tint:0xFFFFFF } );
		}
				
		public function set selected(value:Boolean):void 
		{
			_selected = value;
			
			trace(this);
			
			if (_selected)
			{
				onSelect();
			}else
			{
				onUnselect();
			}
		}
		
		public function get selected():Boolean 
		{
			return _selected;
		}
		
	}

}